<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>设备维护</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/mui.picker.css" />
		<link rel="stylesheet" type="text/css" href="css/mui.depicker.css" />
		<link href="css/comment.css" rel="stylesheet" />
		<link href="css/maintenance.css" rel="stylesheet" />
		<style type="text/css">
			.mui-bar .mui-title{
				left: 80px;
				right: 80px;
			}
		</style>
	</head>
	<body>
		<!-- 侧滑导航根容器 -->
		<div class="mui-off-canvas-wrap mui-slide-in">
			<!-- 菜单容器 -->
			<aside class="mui-off-canvas-right">
				<div class="mui-scroll-wrapper">
					<div class="mui-scroll">
						<!-- 菜单具体展示内容 -->
						<div class="canvasBox">
							<div>设备名称</div>
							<div class="canvasTime">
								<input class="timeText" id="devicename" type="text" value="" placeholder="" />
							</div>
							<div>开始时间</div>
							<div class="canvasTime">
								<input class="timeText canvasTime_start" id="start" readonly type="text" value="" placeholder="" />
							</div>
							<div>结束日期</div>
							<div class="canvasTime">
								<input class="timeText canvasTime_end" id="end" readonly type="text" value="" placeholder="" />
							</div>
							<div class="" style="text-align: center;">
								<button type="button" class="mui-btn mui-btn-primary canvasSubmit">确定</button>
								<button type="button" class="mui-btn mui-btn-warning canvasWarn">取消</button>
							</div>
						</div>
					</div>
				</div>
			</aside>
			<!-- 主页面容器 -->
			<div class="mui-inner-wrap">
				<!-- 主页面标题 -->
				<header class="mui-bar mui-bar-nav gradient_normal">
					<div style="height: 20px;"></div>
					<div class="mui-action-back mui-pull-left mui-icon mui-icon-arrowleft"></div>
					<h1 class="mui-title">设备维护</h1>
					<div class="mui-pull-right mui-icon mui-icon-search searchBtn"></div>
					<div class="mui-pull-right addBtn"><img src="images/mtenadd.png"></div>
					
				</header>
				<div class="mui-content mui-scroll-wrapper">
					<ul class="mui-scroll mten_list">
						<!--动态加载数据-->
						
					</ul>
				</div>
				<div class="mui-off-canvas-backdrop"></div>
			</div>
		</div>
		<div class="mtenModal" id="editModal">
			<form class="mui-input-group">
				<div class="title" id="key" data-id="0">
					<b>设备维护</b>
				</div>
				<div class="mui-input-row">
					<label>问题描述</label>
					<textarea class="problem" id="problem" placeholder="请输入问题描述"></textarea>
				</div>
				<div class="mui-input-row">
					<label>处理方式</label>
					<textarea class="type" id="type" placeholder="请输入处理方式"></textarea>
				</div>
				<div class="mui-input-row">
					<label>维修时间</label>
					<input type="text" id="time" readonly class="mtenTime" placeholder="请输入维修时间">
				</div>
				<div class="mui-input-row">
					<label>维修结果</label>
					<input type="text" id="result" class="result" placeholder="请输入维修结果">
				</div>
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-primary submitBtn">确认</button>
					<button type="button" class="mui-btn mui-btn-warning closeBtn">取消</button>
				</div>
			</form>
		</div>
		<div class="AddModal mtenModal" id="AddModal">
			<form class="mui-input-group">
				<div class="title">
					<b>设备维护</b>
				</div>
				<div class="mui-input-row">
					<label>问题描述</label>
					<textarea class="problem" id="problem1" placeholder="请输入问题描述"></textarea>
				</div>
				<div class="mui-input-row">
					<label>处理方式</label>
					<textarea class="type" id="type1" placeholder="请输入处理方式"></textarea>
				</div>
				<div class="mui-input-row">
					<label>维修时间</label>
					<input type="text" id="time1" readonly class="mtenTime" placeholder="请输入维修时间">
				</div>
				<div class="mui-input-row">
					<label>维修结果</label>
					<input type="text" id="result1" class="result" placeholder="请输入维修结果">
				</div>
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-primary submitBtn">确认</button>
					<button type="button" class="mui-btn mui-btn-warning closeBtn">取消</button>
				</div>
			</form>
		</div>
		<script src="js/mui.js"></script>
		<script src="js/mui.picker.js" type="text/javascript"></script>
		<script src="js/mui.dtpicker.js" type="text/javascript"></script>
		<script src="js/jquery.js"></script>
		<script src="js/rem.js"></script>
		<script type="text/javascript">
			var _url = "http://112.54.80.235:8038";
			mui.init();
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();  
				var info = self.info;
				console.log(info.DeviceNO)
				console.log(info.DeviceName)
				$.ajax({
					type:'get',
					url: _url + '/actionapi/Users/GetWeiHuJiLu',
					data:{
						device:info.DeviceNO,
						devname:info.DeviceName,
						start:"",
						end:""
					},
					dataType: 'json',
					success:function(data){
						var datas=data.data;
						var html="";
						if(data.Code>0){
						var json=JSON.parse(datas)
						
						$(".mten_list").empty();
							for(var i = 0; i < json.length; i++){
								html+='<li class="mui-table-view-cell">';
									html+='<div class="mui-slider-right mui-disabled">';
										html+='<a data-id="'+json[i].Id+'" class="mui-btn mui-btn-yellow edit">编辑</a>';
										html+='<a data-id="'+json[i].Id+'" class="mui-btn mui-btn-red delete">删除</a>';
									html+='</div>';
									html+='<div class="mui-slider-handle">';
										html+='<div class="map_equiment_listItem">';
											html+='<div class="eq_img">';
												html+='<div class="eq_img_title">';
													html+='<span class="eqDe_btn">'+json[i].DeviceName+'</span>';
												html+='</div>';
											html+='</div>';
											html+='<div class="eq_info">';
												html+='<div class="item">';
													html+='<span class="title">问题描述：</span>';
													html+='<span class="info">'+json[i].Problem+'</span>';
												html+='</div>';
												html+='<div class="item">';
													html+='<span class="title">处理方式：</span>';
													html+='<span class="info">'+json[i].Processing+'</span>';
												html+='</div>';
												html+='<div class="item">';
													html+='<span class="title">维修时间：</span>';
													html+='<span class="info">'+json[i].BM_Time+'</span>';
												html+='</div>';
												html+='<div class="item item_flex">';
													html+='<div>';
														html+='<span class="title">维修结果：</span>';
														html+='<span class="info">'+json[i].BM_Result+'</span>';
													html+='</div>';
													html+='<div class="person">';
														html+='<span class="title">负责人：</span>';
														html+='<span class="info">'+json[i].BM_User+'</span>';
													html+='</div>';
												html+='</div>';
											html+='</div>';
										html+='</div>';
									html+='</div>';
								html+='</li>';
							}
						
						}else{
						html+="<li><div class='noData' style='margin-top:30%;'>暂无维修记录</div></li>"
						}
						$(".mten_list").html(html);
					}
				});
				//关闭等待框 
				plus.nativeUI.closeWaiting();
				//新增
				mui('body').on('tap', '.addBtn', function() {
					$('#AddModal').show()
				});
				mui('body').on('tap', '.closeBtn', function() {
					$('.mtenModal').hide()
				});
				//打开搜索
				mui('body').on('tap', '.searchBtn', function() {
					mui('.mui-off-canvas-wrap').offCanvas('show');
				});
				//搜索--开始时间
				mui('body').on('tap', '.canvasTime_start', function() {
					var strPicker = new mui.DtPicker({
						type: 'date'
					});
					strPicker.show(function(e) {
						$('.canvasTime_start').val(e)
					})
				});
				//搜索--结束时间
				mui('body').on('tap', '.canvasTime_end', function() {
					var timestart = $('.canvasTime_start').val();
					var endPicker = new mui.DtPicker({
						type: 'date',
						beginDate: new Date(timestart),
					});
					endPicker.show(function(e) {
						$('.canvasTime_end').val(e)
					})
				});
				//搜索--点击取消搜索按钮
				mui('body').on('tap', '.canvasWarn', function() {
					mui('.mui-off-canvas-wrap').offCanvas('close');
				});
				//搜索--点击确定按钮
				mui('body').on('tap', '.canvasSubmit', function() {
					console.info($("#devicename").val())
					console.info($("#start").val())
					console.info($("#end").val())
					mui('.mui-off-canvas-wrap').offCanvas('close');
					$.ajax({
						type:'get',
						url: _url + '/actionapi/Users/GetWeiHuJiLu',
						data:{
							device:info.DeviceNO,
							devname:$("#devicename").val(),
							start:$("#start").val(),
							end:$("#end").val()
						},
						dataType: 'json',
						success:function(data){
							var datas=data.data;
							var json=JSON.parse(datas)
							var html="";
							$(".mten_list").empty();
							if(data.Code>0){
								for(var i = 0; i < json.length; i++){
									html+='<li class="mui-table-view-cell">';
										html+='<div class="mui-slider-right mui-disabled">';
											html+='<a data-id="'+json[i].Id+'" class="mui-btn mui-btn-yellow edit">编辑</a>';
											html+='<a data-id="'+json[i].Id+'" class="mui-btn mui-btn-red delete">删除</a>';
										html+='</div>';
										html+='<div class="mui-slider-handle">';
											html+='<div class="map_equiment_listItem">';
												html+='<div class="eq_img">';
													html+='<div class="eq_img_title">';
														html+='<span class="eqDe_btn">'+json[i].DeviceName+'</span>';
													html+='</div>';
												html+='</div>';
												html+='<div class="eq_info">';
													html+='<div class="item">';
														html+='<span class="title">问题描述：</span>';
														html+='<span class="info">'+json[i].Problem+'</span>';
													html+='</div>';
													html+='<div class="item">';
														html+='<span class="title">处理方式：</span>';
														html+='<span class="info">'+json[i].Processing+'</span>';
													html+='</div>';
													html+='<div class="item">';
														html+='<span class="title">维修时间：</span>';
														html+='<span class="info">'+json[i].BM_Time+'</span>';
													html+='</div>';
													html+='<div class="item item_flex">';
														html+='<div>';
															html+='<span class="title">维修结果：</span>';
															html+='<span class="info">'+json[i].BM_Result+'</span>';
														html+='</div>';
														html+='<div class="person">';
															html+='<span class="title">负责人：</span>';
															html+='<span class="info">'+json[i].BM_User+'</span>';
														html+='</div>';
													html+='</div>';
												html+='</div>';
											html+='</div>';
										html+='</div>';
									html+='</li>';
								}
							}else{
								html+="<li>搜索结果为0</li>"
							}
							
							$(".mten_list").html(html);
						}
					});
				});
				//点击编辑
				mui('body').on('tap', '.edit', function() {
					var id = $(this).attr('data-id');
					console.log(id);
					$.ajax({
						type:'get',
						url: _url + '/actionapi/Users/GetMaintain',
						data:{
							key:id
						},
						dataType: 'json',
						success:function(data){
							var datas=data.data;
							if(data.Code>0){
								var json=JSON.parse(datas)
								console.info(json.BM_Time)
								$("#problem").val(json.Problem);
								$("#type").val(json.Processing);
								$("#time").val(json.BM_Time);
								$("#result").val(json.BM_Result);
								$("#key").attr("data-id",json.Id);
							}else{
								
							}
							
							
						}
					});
					$('#editModal').show()
				});
				//点击删除
				mui('body').on('tap', '.delete', function() {
					var id = $(this).attr('data-id');
					console.log(id);
					mui.confirm("确定删除该条信息！", "提示信息", ["确定", "取消"], function(e) {
						if (e.index == 0) {
							//删除信息
							console.log(id);
							$.ajax({
								type:'get',
								url: _url + '/actionapi/Users/DeleteMaintain',
								data:{
									key:id
								},
								dataType: 'json',
								success:function(data){
									
									var datas=data.data;
									if(data.result>0){
										window.location.reload();
									}else{
										
									}
									
									
								}
							});
						} 
						
					})
				});
				//时间
				mui('body').on('tap', '.mtenTime', function() { 
					document.activeElement.blur();
					var strPicker = new mui.DtPicker({
						type: 'datetime'
					});
					strPicker.show(function(e) {
						$('.mtenTime').val(e)
					})
				});
				//提交form
				mui('body').on('tap', '.submitBtn', function() {
					var key=$("#key").attr("data-id");
					
					
					console.info(key);
					if(key>0){
						var problem = $('.problem').val();
						var type = $('.type').val();
						var mtenTime = $('.mtenTime').val();
						var result = $('.result').val();
						
						if (problem.length == 0) {
							mui.toast('请输入问题描述')
							return false;
						}
						if (type.length == 0) {
							mui.toast('请输入处理方式')
							return false;
						}
						if (mtenTime.length == 0) {
							mui.toast('请选择维修时间')
							return false;
						}
						if (result.length == 0) {
							mui.toast('请输入维修结果')
							return false;
						}
						$.ajax({
							type:'get',
							url: _url + '/actionapi/Users/UpdateMaintain',
							data:{
								 problem:problem,
								 processing:type,
								 bm_result:result,
								 bm_time:mtenTime,
								 bm_user:"U2",<!--当前登录用户-->
								 key:key
							},
							dataType: 'json',
							success:function(data){
								if(data.result>0){
									
									window.location.reload();
									$('.mtenModal').hide()
								}else{
									console.info(666);
								}
								
								
							}
						});
					}else{
						var problem1 = $("#problem1").val();
						var type1 = $("#type1").val();
						var mtenTime1 = $("#time1").val();
						var result1 = $("#result1").val();
						
						if (problem1.length == 0) {
							mui.toast('请输入问题描述')
							return false;
						}
						if (type1.length == 0) {
							mui.toast('请输入处理方式')
							return false;
						}
						if (mtenTime1.length == 0) {
							mui.toast('请选择维修时间')
							return false;
						}
						if (result1.length == 0) {
							mui.toast('请输入维修结果')
							return false;
						}
						
						console.info(info.DeviceNO);
						console.info(info.DeviceName);
						console.info(problem1);
						console.info(type1);
						console.info(mtenTime1);
						console.info(result1);
						
						$.ajax({
							type:'get',
							url: _url + '/actionapi/Users/MaintainSave',
							data:{
								deviceId:info.DeviceNO,<!--当前设备ID-->
								devicename:info.DeviceName,<!--当前设备名称-->
								problem:problem1,
								processing:type1,
								bm_result:result1,
								bm_time:mtenTime1,
								bm_user:"U1"<!--当前登录用户-->
							},
							dataType: 'json',
							success:function(data){
								
								var datas=data.data;
								if(data.result>0){
									window.location.reload();
									$('.AddModal').hide()
								}else{
									
								}
								
								
							}
						});
					}
				})
			})
		</script>
	</body>
</html>
